﻿<UserControl x:Class="JsdEditor.ShapePreview3D"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:tools="clr-namespace:_3DTools;assembly=3DTools"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             Loaded="UserControl_Loaded"
             MouseWheel="UserControl_MouseWheel">
    <UserControl.Resources>
        <MaterialGroup x:Key="TileMaterial">
            <DiffuseMaterial>
                <DiffuseMaterial.Brush>
                    <SolidColorBrush Color="#DD00FF00" />
                </DiffuseMaterial.Brush>
            </DiffuseMaterial>
            <SpecularMaterial SpecularPower="24">
                <SpecularMaterial.Brush>
                    <SolidColorBrush Color="#FF00FF00" />
                </SpecularMaterial.Brush>
            </SpecularMaterial>
        </MaterialGroup>
        <DiffuseMaterial x:Key="BackTileMaterial">
            <DiffuseMaterial.Brush>
                <SolidColorBrush Color="#DD00FF00" />
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>
        <DiffuseMaterial x:Key="LandMaterial">
            <DiffuseMaterial.Brush>
                <SolidColorBrush Color="#EE660000" />
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>
        <DiffuseMaterial x:Key="LandBackMaterial">
            <DiffuseMaterial.Brush>
                <SolidColorBrush Color="#88FF8888" />
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <DockPanel LastChildFill="False">
            <Button Content="Refresh" DockPanel.Dock="Left" Click="Button_Click" />
        </DockPanel>
        <Border x:Name="b" Grid.Row="1" BorderBrush="Gray" BorderThickness="2" Margin="5" Background="White">
            <tools:TrackballDecorator>
                <Viewport3D>
                    <Viewport3D.Camera>
                        <PerspectiveCamera Position="{Binding CameraPosition}" 
                                           LookDirection="{Binding LookDirection}" />
                    </Viewport3D.Camera>
                    <ModelVisual3D>
                        <ModelVisual3D.Content>
                            <Model3DGroup x:Name="mgRoot">
                                <DirectionalLight Color="White" Direction="-1, -2, 1" />
                                <DirectionalLight Color="White" Direction="1, 2, -1" />
                                <Model3DGroup x:Name="mgShape">
                                    <Model3DGroup.Transform>
                                        <Transform3DGroup>
                                            <RotateTransform3D>
                                                <RotateTransform3D.Rotation>
                                                    <AxisAngleRotation3D x:Name="anrX" Axis="1 0 0" />
                                                </RotateTransform3D.Rotation>
                                            </RotateTransform3D>
                                            <RotateTransform3D>
                                                <RotateTransform3D.Rotation>
                                                    <AxisAngleRotation3D x:Name="anrY" Axis="0 1 0" />
                                                </RotateTransform3D.Rotation>
                                            </RotateTransform3D>
                                            <RotateTransform3D>
                                                <RotateTransform3D.Rotation>
                                                    <AxisAngleRotation3D x:Name="anrZ" Axis="0 0 1" />
                                                </RotateTransform3D.Rotation>
                                            </RotateTransform3D>
                                        </Transform3DGroup>
                                    </Model3DGroup.Transform>
                                </Model3DGroup>
                            </Model3DGroup>
                        </ModelVisual3D.Content>
                    </ModelVisual3D>
                </Viewport3D>
            </tools:TrackballDecorator>
        </Border>
    </Grid>
</UserControl>
